/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ambimmort.ucagent.utils;
import com.ambimmort.ucagent.database.dao.DPIEndPointDao;

import java.sql.SQLException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author 定巍
 */
public class MessageSequenceNoUtil {

//    public static synchronized long getAUsableMessageSequenceNo(int messageType, int dpiEndPointId) throws SQLException {
//        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
//        Transaction tx = s.beginTransaction();
//        Object obj = s.createQuery("SELECT cn FROM CurrentMessageSequenceNo where cn.id.dpiendPointBeanId=" + dpiEndPointId + " and cn.id.policyRepositoryTypeCode='" + HexUtil.getHex((byte) messageType) + "'").uniqueResult();
//        tx.commit();
//        DPIEndPointDao dao = new DPIEndPointDao();
//        
//        if (obj == null) {
//            CurrentMessageSequenceNo bean = new CurrentMessageSequenceNo();
//            bean.setMessageSequenceNo(1);
//            bean.setId(new CurrentMessageSequenceNoId(dpiEndPointId, dao.getPolicyRepositoryInstance(dpiEndPointId, HexUtil.getHex((byte)messageType)).getId()));
//            tx = s.beginTransaction();
//            s.save(bean);
//            tx.commit();
//            return 1;
//        } else {
//            long mn = 0;
//            CurrentMessageSequenceNo bean = (CurrentMessageSequenceNo) obj;
//            mn = bean.getMessageSequenceNo() + 1;
//            bean.setMessageSequenceNo(mn);
//            tx = s.beginTransaction();
//            s.update(bean);
//            tx.commit();
//            return mn;
//        }
//    }
}
